<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Lifts extends Model
{
    use HasFactory;

    protected $table = "lifts";

    protected $fillable = ['name', 'floor_id', 'status'];

    protected $appends = ['floor_info'];

    public function floor()
    {
        return $this->belongsTo(Floor::class, 'floor_id');
    }

    public function message()
    {
        return $this->hasMany(Lifts_Message::class, 'l_id');
    }

    // 假的楼层信息数据，因为要unity那边要做楼层展示
    public function getFloorInfoAttribute($value)
    {
        if ($this->status == 1) {
            $id =  $this->floor_id;
        } else {
            $id = Floor::pluck('id')->random();
        }
        $info = Floor::where(['id' => $id])->first();
        return $info;

    }


}
